﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    public class ChiTietPhieuTraSachBUS
    {
        #region 1. Them
        public static bool ThemChiTietPTS(ChiTietPhieuTraSachDTO chitiet){
            if (!PhieuTraSachDAO.CheckPTSByID(chitiet.MaPhieuTra))
            {
                return false;
            }
            //if(!CuonSachDAO.CheckCuonSachBangID(chitiet.MaTaiLieu) || !KyXBDAO.CheckKyXBByID(chitiet.MaTaiLieu))
            //{
            //    return false;
            //}
            return ChiTietPhieuTraSachDAO.ThemChiTietPhieuTraSach(chitiet);
        }
        #endregion
        #region 2. Sua
        public static bool SuaChiTietPTS(ChiTietPhieuTraSachDTO chitiet){
            if (!PhieuTraSachDAO.CheckPTSByID(chitiet.MaPhieuTra))
            {
                return false;
            }
            if(!CuonSachDAO.CheckCuonSachBangID(chitiet.MaTaiLieu) || !KyXBDAO.CheckKyXBByID(chitiet.MaTaiLieu))
            {
                return false;
            }
            return ChiTietPhieuTraSachDAO.SuaChiTietPhieuTraSach(chitiet);
        }
        #endregion
        #region 3. Xoa
        public static bool XoaChiTietPTS(String mapt, String matl){
            return ChiTietPhieuTraSachDAO.XoaChiTietPhieuTraSach(mapt, matl);
        }
        #endregion
        #region 4. Tim kiem
        public static ChiTietPhieuTraSachDTO TimChiTietPTS(String mapt, String matl){
            return ChiTietPhieuTraSachDAO.TimChiTietPTSByID(mapt, matl);
        }
        public static DataTable TimChiTietPTSByPhieuTra(String mapt){
            return ChiTietPhieuTraSachDAO.TimChiTietPTSByPhieuTra(mapt);
        }
        public static List<ChiTietPhieuTraSachDTO> TimChiTietPTSByTaiLieu(String matl)
        {
            return ChiTietPhieuTraSachDAO.TimChiTietPhieuTraSachByTaiLieu(matl);
        }
        public static int TinhSoNgayTreCuaTaiLieu(String matl){
            return ChiTietPhieuTraSachDAO.TinhSoNgayTreCuaTaiLieu(matl);
        }
        #endregion
    }
}
